//package com.wanji.single_point.controller;
//
//
//import com.wanji.single_point.entity.Alarm;
//import com.wanji.single_point.entity.Count;
//import com.wanji.single_point.entity.Radar;
//import com.wanji.single_point.pojo.PutParam;
//import com.wanji.single_point.service.AlarmService;
//import com.wanji.single_point.service.CountService;
//import com.wanji.single_point.service.RadarService;
//import net.sf.json.JSONArray;
//import org.apache.kafka.clients.consumer.ConsumerRecord;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.kafka.annotation.KafkaListener;
//import org.springframework.web.bind.annotation.*;
//
//import java.util.Arrays;
//import java.util.HashMap;
//import java.util.Map;
//import java.util.Optional;
//import java.util.concurrent.ConcurrentHashMap;
//
///**
// * 单点感知测试  控制器
// *
// * @Date: 2022-06-25
// */
//@CrossOrigin
//@RequestMapping("/perceptionTest")
//@RestController
//public class PerceptionTestController {
//    private static final Logger logger = LoggerFactory.getLogger(PerceptionTestController.class);
//
//
//    @Autowired
//    private CountService countService;
//    @Autowired
//    private AlarmService alarmService;
//    @Autowired
//    private RadarService radarService;
//    /**
//     * 接受 事件报警数据
//     *
//     * @Date: 2022-06-23
//     */
//    @KafkaListener(topics = "radar.alarm")
//    public void consumerAlarm(ConsumerRecord<?, ?> record) {
//        Optional<?> kafkaMessage = Optional.ofNullable(record.value());
//        if (kafkaMessage.isPresent()) {
//            Object message = kafkaMessage.get();
////            logger.info("警报");
//            logger.info(message.toString());
//            Alarm[] bodiesReal = (Alarm[]) JSONArray.toArray(JSONArray.fromObject(message), Alarm.class);
////            Map<String, PutParam> user = ComController.user;
////            for (String key : user.keySet()) {
////
////            }
//            String realCode = "GW42940404";
//            String testCode = "GW42940404";
//            Long beginTime = 1560802113491L;
//            Long endTime = 1760802113491L;
//            PutParam param = countService.putParamer(realCode, testCode, beginTime, endTime);
//            String deviceId = "962464";
//            String userId = deviceId + realCode + testCode;
//            alarmService.putData(userId, bodiesReal, bodiesReal, param);
//        }
//    }
//
//
//    /**
//     * 接受 跟踪数据
//     *
//     * @Date: 2022-06-23
//     */
//    @KafkaListener(topics = "radar.track")
//    public void consumerTrack(ConsumerRecord<?, ?> record) {
//        Optional<?> kafkaMessage = Optional.ofNullable(record.value());
//        if (kafkaMessage.isPresent()) {
//            Object message = kafkaMessage.get();
////            logger.info("跟踪");
////            logger.info(message.toString());
//            Radar[] bodiesTest = (Radar[]) JSONArray.toArray(JSONArray.fromObject(message), Radar.class);
////            System.out.println(Arrays.toString(bodiesTest));
////            System.out.println(bodiesTest);
//
//            String realCode = "GW42940407";
//            String testCode = "GW42940407";
//            Long beginTime = 1560802113491L;
//            Long endTime = 1760802113491L;
//            PutParam param = radarService.putParamer(realCode, testCode, beginTime, endTime);
//            String deviceId = "962464";
//            String userId = deviceId + realCode + testCode;
//            radarService.putData(userId, bodiesTest, bodiesTest,param);
//        }
//    }
//
//    /**
//     * 接受 统计数据
//     *
//     * @Date: 2022-06-25
//     */
//    @KafkaListener(topics = "radar.count")
//    public void consumerRadarCount(ConsumerRecord<?, ?> records) {
//        Optional<?> kafkaMessage = Optional.ofNullable(records.value());
//        if (kafkaMessage.isPresent()) {
//            Object message = kafkaMessage.get();
////            logger.info("统计");
//            Count[] bodiesReal = (Count[]) JSONArray.toArray(JSONArray.fromObject(message.toString()), Count.class);
//
//            Count countReal = bodiesReal[0];
//            String realCode = "GW42940400";
//            String testCode = "GW42940400";
//            Long beginTime = 1560802113491L;
//            Long endTime = 1760802113491L;
//            PutParam param = countService.putParamer(realCode, testCode, beginTime, endTime);
//            String deviceId = "962464";;
//            String userId = deviceId + realCode + testCode;
//            countService.putData(userId, countReal, countReal,param);
//        }
//    }
//
//}
